package com.css.fxfzaqbz.modules.assess2.controller;


import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.assess2.entity.KeyplaceRiskassessment;
import com.css.fxfzaqbz.modules.assess2.entity.UTask;
import com.css.fxfzaqbz.modules.assess2.entity.UrgencysettleData;
import com.css.fxfzaqbz.modules.assess2.service.UTaskService;
import com.css.fxfzaqbz.modules.assess2.service.UrgencysettleDataService;
import com.css.fxfzaqbz.modules.assess2.vo.UrgencysettleVO;
import com.css.fxfzaqbz.modules.data.vo.AidedAnalyseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/*
 * 紧急安置人员数据
 * */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class UrgencysettleDataController {
    @Resource
    UrgencysettleDataService urgencysettleDataService;

    /**
     * 新增urgencysettleData
     *
     * @param urgencysettleData
     * @return
     */
    @PostMapping("/saveUrgencysettleData")
    public RestResponse saveUrgencysettleData(@RequestBody UrgencysettleData urgencysettleData) {
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.saveUrgencysettleData(urgencysettleData);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("新增紧急安置人员数据失败", e);
            restResponse = RestResponse.fail("新增紧急安置人员数据失败!");
        }
        return restResponse;
    }


    @PostMapping("/saveUrgencysettleDataByPG")
    public RestResponse saveUrgencysettleDataByPG(@RequestBody UrgencysettleVO urgencysettleVO) {
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.saveUrgencysettleDataByPG(urgencysettleVO);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("新增紧急安置人员数据失败", e);
            restResponse = RestResponse.fail("新增紧急安置人员数据失败!");
        }
        return restResponse;
    }




    /**
     * 根据id查询urgencysettleData数据
     * @param id
     * @return
     */
    @GetMapping("/getUrgencysettleDataById/{id}")
    public RestResponse getUrgencysettleDataById(@PathVariable("id") String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(urgencysettleDataService.getUrgencysettleDataById(id));
        } catch (Exception e) {
            log.error("获取紧急安置人员数据失败!", e);
            restResponse = RestResponse.fail("获取紧急安置人员数据失败!");
        }
        return restResponse;
    }

    /**
     * 根据id逻辑删除，修改数据标志位
     *
     * @param id
     * @return
     */
    @PostMapping("/delUrgencysettleData/{id}")
    public RestResponse deleteUrgencysettleData(@PathVariable("id") String id) {
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.deleteUrgencysettleData(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除紧急安置人员数据失败!", e);
            restResponse = RestResponse.fail("删除紧急安置人员数据失败!");
        }
        return restResponse;
    }

    /**
     * 修改
     *
     * @param urgencysettleData
     * @return
     */
    @PostMapping("/updateUrgencysettleData")
    public RestResponse<UrgencysettleData> updateUrgencysettleData(@RequestBody UrgencysettleData urgencysettleData) {
        RestResponse restResponse = null;
        try {
            UrgencysettleData urgencysettleData1 = urgencysettleDataService.updateUrgencysettleData(urgencysettleData);
            restResponse = RestResponse.succeed(urgencysettleData1);
        } catch (Exception e) {
            log.error("修改紧急安置人员数据失败!", e);
            restResponse = RestResponse.fail("修改紧急安置人员数据失败!");
        }
        return restResponse;
    }


    /**
     * 读取附件信息
     *
     * @param udFileId
     * @return
     */

    @GetMapping("/getExcel")
    public RestResponse getExcel(@RequestParam("udFileId") String udFileId) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(urgencysettleDataService.getExcel(udFileId));
        } catch (Exception e) {
            log.error("读取失败", e);
            restResponse = RestResponse.fail("读取失败");
        }
        return restResponse;
    }


    /**
     *根据活动id全查-过程稿
     * @param id
     * @return
     */
    @GetMapping("/getUrgencysettleDataByIaId/{id}")
    public RestResponse getUrgencysettleDataByIaId(@PathVariable("id") String id) {
        try {
            List<UrgencysettleData> urgencysettleDatas = urgencysettleDataService.getUrgencysettleDataByIaId(id);
            return RestResponse.succeed(urgencysettleDatas);
        } catch (Exception e) {
            log.error("查看失败", e);
            return RestResponse.fail("查看失败");
        }
    }

    /**
     *根据活动id全查-最终成果
     * @param id
     * @return
     */
    @GetMapping("/getUrgencysettleDataByActiveId/{id}")
    public RestResponse getUrgencysettleDataByActiveId(@PathVariable("id") String id) {
        try {
            List<UrgencysettleData> urgencysettleDatas = urgencysettleDataService.getUrgencysettleDataByActiveId(id);
            return RestResponse.succeed(urgencysettleDatas);
        } catch (Exception e) {
            log.error("查看失败", e);
            return RestResponse.fail("查看失败");
        }
    }

    /**
     * 重复校验
     * @param urgencysettleData
     * @return
     */
    @PostMapping("/checkUrgencysettleData")
    public RestResponse check(@RequestBody UrgencysettleData urgencysettleData){
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(urgencysettleDataService.check(urgencysettleData));
        } catch (Exception e) {
            log.error("重复校验失败!", e);
            restResponse = RestResponse.fail("重复校验失败!");
        }
        return restResponse;
    }


    /**
     * 评估内容重复校验接口
     * @param urgencysettleData
     * @return
     */
    @PostMapping("/isCheck")
    public RestResponse isCheck(@RequestBody UrgencysettleData urgencysettleData){
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(urgencysettleDataService.isCheck(urgencysettleData));
        } catch (Exception e) {
            log.error("重复校验失败!", e);
            restResponse = RestResponse.fail("重复校验失败!");
        }
        return restResponse;
    }

    /**
     * 提交最终成果
     * @param id
     * @return
     */
    @PostMapping("/submitResultUrgencysettleData")
    public RestResponse submitResult(String id){
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.submitResult(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("提交最终成果失败!", e);
            restResponse = RestResponse.fail("提交最终成果失败!");
        }
        return restResponse;
    }
    /**
     * 添加描述
     * @param aidedAnalyseVo
     * @return
     */
    @PostMapping("/saveDescriptionUrgencysettleData")
    public RestResponse saveDescription(@RequestBody AidedAnalyseVo aidedAnalyseVo) {
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.saveDescription(aidedAnalyseVo);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("添加描述失败!", e);
            restResponse = RestResponse.fail("添加描述失败!");
        }
        return restResponse;
    }

    /**
     * 移除最终成果
     * @param id
     * @return
     */
    @PostMapping("/removeResultUrgencysettleData")
    public RestResponse removeResult(String id){
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.removeResult(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("移除最终成果失败!", e);
            restResponse = RestResponse.fail("移除最终成果失败!");
        }
        return restResponse;
    }
    /**
     * 最终提交
     * @param ids
     * @return
     */
    @PostMapping("/finalSubmissionUrgencysettleData/{ids}")
    public RestResponse finalSubmission(@PathVariable("ids") List<String> ids){
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.finalSubmission(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("最终提交失败!", e);
            restResponse = RestResponse.fail("最终提交失败!");
        }
        return restResponse;
    }

    /**
        校验最终成果里是否有数据 （最终成果只能存在一条数据）
     */
    @GetMapping("/getNum/{iaId}")
    public RestResponse getNum(@PathVariable("iaId") String iaId){
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(urgencysettleDataService.getNum(iaId));
        } catch (Exception e) {
            log.error("校验失败!", e);
            restResponse = RestResponse.fail("校验失败!");
        }
        return restResponse;
    }
    /**
     覆盖接口 （最终成果只能存在一条数据）
     */
    @GetMapping("/cover")
    public RestResponse cover(String iaId,String id){
        RestResponse restResponse = null;
        try {
            urgencysettleDataService.cover(iaId,id);
            restResponse = RestResponse.succeed("覆盖成功");
        } catch (Exception e) {
            log.error("覆盖失败!", e);
            restResponse = RestResponse.fail("覆盖失败!");
        }
        return restResponse;
    }



}
